#include "digit_property.h"
/*
 * priority of operators
 * NOTE: smaller value means higher priority
 * */
const char *priority[] = {"*/", "+-"};

char *braces = "(){}[]";
int find_index(const char *string, char letter) {
  const char *p;
  for (p = string; *p && *p != letter; p++)
    ;
  return p - string;
}
bool is_opend(char c) {
  if (c >= 'a' && c <= 'z')
    return true;
  if (c >= 'A' && c <= 'Z')
    return true;
  if (c >= '1' && c <= '9')
    return true;
  if (c == '0')
    return true;
  return false;
}
/*
 * NOTE: smaller value means higher priority
 */
int get_priority(char c) {
  int i = 0;
  for (; i < sizeof(priority) / sizeof(char *); i++) {
    const char *priority_candidate = priority[i];
    char match = priority_candidate[find_index(priority_candidate, c)];
    if (match)
      return i;
  }
  return i;
}

int is_calc(char c) {
  return get_priority(c) <= sizeof(priority) / sizeof(char *);
}
